package com.timebank.volunteer.controller;

import com.timebank.common.core.web.controller.BaseController;
import com.timebank.common.core.web.page.TableDataInfo;
import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.common.log.annotation.Log;
import com.timebank.common.log.enums.BusinessType;
import com.timebank.common.security.annotation.RequiresLogin;
import com.timebank.volunteer.pojo.entity.VolunteerBlackList;
import com.timebank.volunteer.pojo.vo.VolunteerBlackListVO;
import com.timebank.volunteer.service.VolunteerBlackListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 志愿服务 黑名单
 * @author shiliuyinzhen
 */
@RestController
@RequestMapping("/blackList")
@Api(tags = "志愿服务黑名单相关接口")
public class VolunteerBlackListController extends BaseController {

    @Resource
    private VolunteerBlackListService volunteerBlackListService;

    /**
     * 根据志愿服务Id获取黑名单
     * @param volunteerId
     * @return
     */
    @RequiresLogin
    @GetMapping("/list/{volunteerId}")
    @ApiOperation("根据志愿服务Id获取黑名单")
    public TableDataInfo getBlackListByVolunteerId(@PathVariable("volunteerId") Long volunteerId){
        startPage();
        List<VolunteerBlackListVO> list = volunteerBlackListService.getBlackListByVolunteerId(volunteerId);
        return getDataTable(list);
    }

    /**
     * 根据志愿服务Id和用户Ids批量移除黑名单
     * @param userIds
     * @param map
     * @return
     */
    @DeleteMapping("/user/{userIds}")
    @Log(title = "志愿服务黑名单", businessType = BusinessType.DELETE)
    @ApiOperation("根据志愿服务Id和用户Ids批量移除黑名单")
    public AjaxResult removeBlackListByVolunteerIdAndUserIds(@PathVariable("userIds") Long[] userIds, @RequestBody Map<String,Long> map){
        Long volunteerId = map.get("volunteerId");
        return toAjax(volunteerBlackListService.removeBlackListByVolunteerIdAndUserIds(volunteerId,userIds));
    }
}
